package edu.gdkm.demo12;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class FileDemo {
    //读取花名册并使用List储存每位同学的姓名
    public static void main(String[] args) throws IOException {
        File file = new File("./facebook.txt");
        FileReader fr = new FileReader(file);
        //使用缓存流实现文件的逐行读取
        BufferedReader br=new BufferedReader(fr);
        String name;
//        int count=0;
//        while((name =br.readLine())!=null){
//            count++;
//        }
//         String students[] = new String[count]; 、、count需要读取一次完整的文本后才能获得
        ArrayList<String> students = new ArrayList<>();
//        while((name =br.readLine())!=null){
//            students[count++]=name;
//        }
        while((name =br.readLine())!=null){
            students.add(name);
        }
        System.out.println(students);
//        for(String student:students){
//            System.out.println(student);
//        }

    }

}
